<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="common/layout :: common_header(~{::title},~{::link})">
<title>短信记录</title>
<!-- 
  additional css  -->

</head>

<body>
	<div class="main-container">
		<div class="main-content-inner">
			<div class="page-content">
				<div class="page-header">
					<h1>短信记录</h1>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<form action="" class="form-inline" id="userForm">

							<label>短信模板：</label>
							<select name="templateCode">
								<option value="">请选择...</option>
                        		<option  th:each="template:${tempList}" th:value="${template.code}" th:text="${template.name }"></option>
							</select>
							 
							<label>手机号码：</label><input type="text" name="phone"> 
							<button class="btn btn-primary btn-rounded btn-outline btn-sm "
								type="button" onclick="search()">
								<i class="fa fa-search"></i> 查询
							</button>
							 <a href="javascript:void(0);" onclick="delSms()"  class=" pull-right">一键删除未发送短信</a>
						</form>
					</div>
				</div>

				<div class="row">
					<div class="col-xs-12">
						<table id="usertable" data-toggle="table"
							data-side-pagination="server" data-striped="true"
							data-query-params="queryParams" data-pagination-loop="false"
							data-page-number="1" data-data-field="list"
							data-total-field="totalRow"
							data-content-type="application/x-www-form-urlencoded"
							data-click-to-select="true" data-pagination="true"
							data-method="post" th:data-url="@{/sms/smsRecord/query}">
							<thead>
								<tr>
									<th data-field="id">编号</th>
									<th data-field="phone">手机号码</th>
									<th data-field="templateCode">模板名称</th>
									<th data-field="param">短信内容</th>
									<th data-field="createTime"><i
										class="ace-icon fa fa-clock-o bigger-110 hidden-480"></i> 创建时间</th>
									<th data-field="sendtime"><i
										class="ace-icon fa fa-clock-o bigger-110 hidden-480"></i> 发送时间</th>
									<th data-field="state" data-formatter="statusFormatter">状态</th>
								</tr>
							</thead>
						</table>
					</div>

				</div>
				<!-- /.col -->
			</div>

		</div>
		<!-- end main container -->
	</div>

	<div th:replace="common/commonJS"></div>
	<script>

	 function queryParams(params){
		 var temp = $("#userForm").serializeJSON();
		 temp.pageSize=params.limit;   //页面大小
		 temp.pageNumber=(params.offset / params.limit) + 1;   //页码  
		 temp.sort=params.sort;      //排序列名  
		 temp.sortOrder=	 params.order; //排位命令（desc，asc）
		 return temp; 
	 }
    function statusFormatter(value,row,index){
    	//0未发送，1已发送，2成功，3失败
    	if(value=="1"){
    		return "<span class='label label-sm label-success'>已发送</span>"
    	}else if(value=="0"){
    		return "<span class='label label-sm label-warning'>未发送</span>";
    	}else if(value=="2"){
    		return "<span class='label label-sm label-success'>发送成功</span>"
        }else if(value=="3"){
        	return "<span class='label label-sm label-warning'>发送失败</span>";
        }
    }
    
    function search(){
    	$('#usertable').bootstrapTable('refresh');
    }
    /**
    *一键删除未发送短信
    **/
	function delSms(){
		jp.confirm('确定要删除选择吗？', function (){
			 jp.loading();
     	  	$.get(ctx+"sms/smsRecord/deleteSms", function(data){
     	  		if(data){
     	  			$('#usertable').bootstrapTable('refresh');
    	  			jp.success("删除成功");
    	  		}else{
    	  			jp.error("删除失败");
    	  		}
     	  	})

		 }
		
	);

		} 
</script>
</body>
</html>